package com.cgtong.android.mvp.presenter;

import com.blankj.utilcode.util.ToastUtils;
import com.cgtong.android.R;
import com.cgtong.android.mvp.contract.ForgetPasswordContract;
import com.cgtong.android.mvp.model.ForgetPasswordModel;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

/**
 * Created by Sky.Bing on 2017/10/23.
 */

public class ForgetPasswordPresenter implements ForgetPasswordContract.Presenter {
    private ForgetPasswordContract.Model mModel;
    private ForgetPasswordContract.View mView;

    public ForgetPasswordPresenter(ForgetPasswordContract.View view) {
        mView = view;
        mModel = new ForgetPasswordModel();
    }

    @Override
    public void sendValidCode(String phone) {
        mModel.sendValidCode(phone, new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object o) {
                mView.breakClickValidCode();
            }

            @Override
            public void onError(ApiException e) {
                mView.onSendValidCodeError(e);
            }
        });
    }

    @Override
    public void saveForgetPwd(String confirmPassword, String mobile, String newPassword, String validCode) {
        mModel.saveForgetPwd(confirmPassword, mobile, newPassword, validCode, new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object o) {
                mView.onSaveForgetPwdSuccess();
            }

            @Override
            public void onError(ApiException e) {
                mView.onSaveForgetPwdError(e);
            }
        });
    }
}